﻿using MediatR;
using Medical.Api.Write.Application.Command.PackagingSterilization;
using Medical.Api.Write.Application.Command.PackagingSterilization.SterilizationRegistration;
using Medical.ErrorCode;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Medical.Api.Write.Controllers
{
    /// <summary>
    /// 包装灭菌
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class PackagingSterilizationController : ControllerBase
    {
        private readonly IMediator mediator;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="mediator"></param>
        public PackagingSterilizationController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 添加包装登记实体
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        [HttpPost]
        public Task<ApiResult<int>> AddPackagingRegistration(AddPackagingRegistrationCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 删除包装方法
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpGet]
        public Task<ApiResult<int>> DelPackagingSterilization([FromQuery]DeletePackagingSterilizationCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 添加灭菌登记实体
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<ApiResult<int>> AddSterilizationRegistration(AddSterilizationRegistrationCommand request)
        {
            return mediator.Send(request);
        }
        /// <summary>
        /// 修改灭菌状态
        /// </summary>
        /// <param name="request">修改灭菌状态命令</param>
        /// <returns>操作结果</returns>
        [HttpPut]
        public async Task<ApiResult<int>> UpdateSterilizationState([FromBody] UpdateSterilizationStateCommand request)
        {
            try
            {
                var result = await mediator.Send(request);
                return result;
            }
            catch (Exception ex)
            {
                return new ApiResult<int>
                {
                    Code = ApiEnums.Error,
                    Data = 0,
                    Msg = "修改灭菌状态失败：" + ex.Message
                };
            }
        }
    }
}
